import pytest_check as c
from colorama import Fore

"""
描述:检查结果
1.将如下3句，优化成1句
    assert r.json()['msg']== add_data['expect']['msg']
    assert r.json()['status'] == add_data['expect']['status']
    assert r.json()['code']== add_data['expect']['code']
2.断言失败后，代码不会中断。
    assertEqual(real,expect，keys)
    assertEqual(r.json(),add_data['expect'], ['msg', 'status', 'code'])
    使用pytest_check 模块中的方法
"""


def assertEqual(real, expect, keys):
    for key in keys:
        r = real.get(key)
        e = expect.get(key)
        if c.equal(r, e):
            print(Fore.GREEN, f"校验{key}通过", Fore.RESET)
        else:
            print(Fore.RED, f"校验{key}失败，实际结果为：{r}，预期结果为：{e}", Fore.RESET)
